import 'package:play_android/com/zhihaoliang/http/HttpException.dart';
import 'package:play_android/com/zhihaoliang/base/BaseRepository.dart';
import 'package:play_android/com/zhihaoliang/const/AppApi.dart';
import 'package:play_android/com/zhihaoliang/http/ResultData.dart';
import 'package:play_android/com/zhihaoliang/http/HttpRequest.dart';

///  ***************************************************************************
///  "登录"请求处理
///  ***************************************************************************

class LikePresenter extends BaseRepository {
  LikeModelCallBack _likeModelCallBack;

  LikePresenter(this._likeModelCallBack);

  load(bool isLike, int id) {
    String url = isLike ? AppApi.UNCOLLECT_ORIGINID : AppApi.COLLECT;
    url += '$id/json';
    fetch(url)
        .then((_) => _likeModelCallBack.onLikeComplete())
        .catchError((onError) => _likeModelCallBack.onLikeError(onError));
  }

  @override
  fetchModel(Map<String, dynamic> map) {
    return null;
  }

  @override
  Future<ResultData> fetchResultData(
      [String url, Map<String, dynamic> map]) async {
    return await HttpRequest().post(url, map);
    ;
  }
}

abstract class LikeModelCallBack {
  void onLikeComplete();

  void onLikeError(HttpException httpException);
}
